package com.vaadin.lab6;

import java.util.Set;

import com.vaadin.data.Item;
import com.vaadin.data.util.PropertyFormatter;
import com.vaadin.ui.Component;
import com.vaadin.ui.DefaultFieldFactory;
import com.vaadin.ui.Field;
import com.vaadin.ui.OptionGroup;
import com.vaadin.ui.TextField;

@SuppressWarnings("serial")
public class MyFieldFactory extends DefaultFieldFactory {

	@Override
	public Field createField(Item item, Object propertyId, Component uiContext) {
		
		if(Set.class.isAssignableFrom(item.getItemProperty(propertyId).getType())){
			OptionGroup group = new OptionGroup();
			group.setMultiSelect(true);
			group.addItem("first");
			group.addItem("two");
			group.addItem("three");
			return group;
		}
		
		if(Double.class.equals(item.getItemProperty(propertyId).getType())){
			TextField field = new TextField();
			MypropertyFormatter pf = new MypropertyFormatter();
			pf.setPropertyDataSource(item.getItemProperty(propertyId));
			field.setPropertyDataSource(pf);
			return field;
		}
		return super.createField(item, propertyId, uiContext);
	}
	
	
}
